package net.entelijan.cobean.util;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;


public class SelectionIntervalTestCase {
	
	@Test
	public void test01() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(1,2);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(0, i.get(0).getFrom());
		assertEquals(1, i.get(0).getTo());
	}

	@Test
	public void test02() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(1,2,3);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(0, i.get(0).getFrom());
		assertEquals(2, i.get(0).getTo());
	}

	@Test
	public void test03() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(2,3);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(1, i.get(0).getFrom());
		assertEquals(2, i.get(0).getTo());
	}

	@Test
	public void test04() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(2,3,4,5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(1, i.get(0).getFrom());
		assertEquals(4, i.get(0).getTo());
	}

	@Test
	public void test05() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(2,3,4,6);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(1, i.get(0).getFrom());
		assertEquals(3, i.get(0).getTo());
	}

	@Test
	public void test06() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(2);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(1, i.get(0).getFrom());
		assertEquals(1, i.get(0).getTo());
	}

	@Test
	public void test07() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(4, i.get(0).getFrom());
		assertEquals(4, i.get(0).getTo());
	}

	@Test
	public void test08() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(4,5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(1, i.size());
		assertEquals(3, i.get(0).getFrom());
		assertEquals(4, i.get(0).getTo());
	}

	@Test
	public void test09() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(1,4,5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(2, i.size());
		assertEquals(0, i.get(0).getFrom());
		assertEquals(0, i.get(0).getTo());
		assertEquals(3, i.get(1).getFrom());
		assertEquals(4, i.get(1).getTo());
	}

	@Test
	public void test10() {
		List<Integer> d = createIntList(1,2,3,4,5);
		List<Integer> s = createIntList(1,2,4,5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(2, i.size());
		assertEquals(0, i.get(0).getFrom());
		assertEquals(1, i.get(0).getTo());
		assertEquals(3, i.get(1).getFrom());
		assertEquals(4, i.get(1).getTo());
	}

	@Test
	public void test11() {
		List<Integer> d = createIntList(1,4,3,2,5);
		List<Integer> s = createIntList(1,2,4,5);
		List<Interval> i = CobeanUtil.createSelectionIntervals(d, s);
		assertEquals(2, i.size());
		assertEquals(0, i.get(0).getFrom());
		assertEquals(1, i.get(0).getTo());
		assertEquals(3, i.get(1).getFrom());
		assertEquals(4, i.get(1).getTo());
	}

	private List<Integer> createIntList(Integer... vals ) {
		ArrayList<Integer> re = new ArrayList<Integer>();
		for (Integer i : vals) {
			re.add(i);
		}
		return re;
	}

}
